/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2020 All Rights Reserved.
 */
package com.suxiaoxiao.springbootlearn.designpattern.templatepattern.jdk;

/**
 * JDK 中的 Comparable 使用了模板方法模式
 *
 * @author zhaorongzhang
 * @version Ducj.java, v 0.1 2020/1/4 4:17 下午 zhaorongzhang Exp $$
 */
public class Duck implements Comparable {

    private String name;
    private int weight;

    public Duck(String name, int weight) {
        this.name = name;
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Duck{" +
                "name='" + name + '\'' +
                ", weight=" + weight +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        Duck otherDuck = (Duck) o;
        // 帅啊, 使用 Integer 类中的 compare 方法
        return Integer.compare(this.weight, otherDuck.weight);
    }

}